#include "kdcconfigdialog.h"

#include "kdcconfig.h"
#include "kdcgeneralconfigpage.h"
#include "kdcfilefactory.h"

#include <KIcon>
#include <KLocale>
#include <KPageWidgetItem>
#include <interfaces/kdcapplicationinterface.h>
extern KDCApplicationInterface *gKDCApplicationInterface;

KDCConfigDialog::KDCConfigDialog( QWidget *aParent ) : KConfigDialog( aParent, i18n("settings"), KDCConfig::self() ), pPluginsPage( NULL ) 
{
	setWindowIcon( gKDCApplicationInterface->appIcon() );
	setMinimumSize( 750, 500 );

	pPages.append( new KDCGeneralConfigPage( this ) );
	addPage( pPages.last(), i18n("General\nOptions"), "configure", i18n("General Options") );
	pPluginsPage = new KDCPluginsConfigPage( this );
	connect( pPluginsPage, SIGNAL( addPluginPage( KDCConfigPageInterface *, const QString &, const KIcon & ) ), this, SLOT( addPluginPage( KDCConfigPageInterface *, const QString &, const KIcon & ) ) );
	addPage( pPluginsPage, i18n("Plugins"), "preferences-plugin", i18n("Plugins") );
}

KDCConfigDialog::~KDCConfigDialog()
{

}

void KDCConfigDialog::loadSettings()
{
	foreach( KDCConfigPageInterface *page, pPages )
		page->load();
}

void KDCConfigDialog::saveSettings()
{
	foreach( KDCConfigPageInterface *page, pPages )
		page->save();
	KDCConfig::self()->writeConfig();
}

KDCPluginsConfigPage* KDCConfigDialog::pluginPage() const
{
	return pPluginsPage;
}

void KDCConfigDialog::addPluginPage( KDCConfigPageInterface *aPageWidget, const QString &aPageName, const KIcon &aPageIcon )
{
	KPageWidgetItem *item = addPage( aPageWidget, aPageName );
	item->setIcon( aPageIcon );
	pPages.append( aPageWidget );
}
